package service

import (
	"chat_srv/basic/config"
	chat "chat_srv/basic/proto"
	"chat_srv/handler/dao"
	"context"
)

type Server struct {
	chat.UnimplementedChatServer
}

// 发送消息（私聊）
func (s *Server) SendMessage(_ context.Context, in *chat.SendMessageReq) (*chat.SendMessageResp, error) {
	// 业务逻辑：发送消息
	message, err := dao.SendMessage(config.Ctx, in)
	if err != nil {
		return nil, err
	}
	return &chat.SendMessageResp{
		MessageId: message.ConversationId,
		Message:   message.Content,
	}, nil
}

// 获取会话消息（私聊）
func (s *Server) GetMessage(_ context.Context, in *chat.GetMessageReq) (*chat.GetMessageResp, error) {
	// 业务逻辑：获取会话消息
	messages, err := dao.GetConversationMessages(config.Ctx, in)
	if err != nil {
		return nil, err
	}
	return &chat.GetMessageResp{
		Messages: messages,
	}, nil
}
